package com.dream.inspect.modules.business.controller;


import com.dream.inspect.common.utils.PageUtils;
import com.dream.inspect.common.utils.R;
import com.dream.inspect.modules.business.dao.SysXzqhDao;
import com.dream.inspect.modules.business.entity.SysXzqhEntity;
import com.dream.inspect.modules.business.service.SuperviseStandardService;
import com.dream.inspect.modules.business.service.SysXzqhService;
import com.dream.inspect.modules.sys.controller.AbstractController;
import com.dream.inspect.modules.sys.entity.SysUserEntity;
import com.dream.inspect.modules.sys.service.SysDeptService;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * 常用功能
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-06-16 17:04:56
 */
@RestController
@CrossOrigin
@RequestMapping("business/statisial")
public class StatisticalAnalysisController extends AbstractController{

    @Autowired
    private SysDeptService sysDeptService;
    @Autowired
    private SuperviseStandardService superviseStandardService;
    @Autowired
    private SysXzqhService sysXzqhService;
    @Autowired
    private SysXzqhDao sysXzqhDao;

    @RequestMapping("deptlist")
    public R deptlist(@RequestParam Map<String, Object> params){
        SysUserEntity user = getUser();
        params.put("deptId", user.getDeptId());
        params.put("userId", user.getUserId());
        if(params.containsKey("xzqhId")){
            params.put("level",sysXzqhDao.selectById(params.get("xzqhId").toString()).getLevel());
        }
        PageUtils page = sysDeptService.findDeptQuestionList(params);
        return R.ok().put("page", page);
    }

    @RequestMapping("questionlist")
    public R questionlist(@RequestParam Map<String, Object> params){
        SysUserEntity user = getUser();
        params.put("deptId", user.getDeptId());
        params.put("userId", user.getUserId());
        if(params.containsKey("xzqhId")){
            params.put("level",sysXzqhDao.selectById(params.get("xzqhId").toString()).getLevel());
        }
        PageUtils page = superviseStandardService.findQuestionList(params);
        return R.ok().put("page", page);
    }

    /**
     * 查询区划
     */
    @RequestMapping("getXzqhTreeList")
    public R getXzqhTreeList(){
        List<SysXzqhEntity>  list = sysXzqhService.findProvincesAndCities();

        return R.ok().put("data",list);
    }
}
